package com.leyou.search.listener;

import com.leyou.search.service.IndexService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author mySun
 * @create 2021-07-24 12:02
 */
@Component
public class ItemListener {
    @Autowired
    private IndexService indexService;


    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(name = "item.queue.up",durable = "true"),
                    exchange = @Exchange(name = "jhj",type = ExchangeTypes.TOPIC),
                    key ="item.up"
            )
    )
    public void goodsUp(Long spuId){
        indexService.saveGoods(spuId);
    }

    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(name = "item.queue.down",durable = "true"),
                    exchange = @Exchange(name = "jhj",type = ExchangeTypes.TOPIC),
                    key = "item.down"
            )
    )
    public void goodsDown(Long spuId){
        indexService.deleteGoods(spuId);
    }


}
